// UITeZheng4Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "JianAiSSQ.h"
#include "UITeZheng4Dlg.h"
#include "help.h"
#include "IniFile.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CUITeZheng4Dlg dialog


CUITeZheng4Dlg::CUITeZheng4Dlg(CWnd* pParent /*=NULL*/)
	: CTabPageSSL(CUITeZheng4Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUITeZheng4Dlg)
	m_strPD1 = _T("");
	m_strPD2 = _T("");
	m_strPD3 = _T("");
	m_strPD4 = _T("");
	m_strPD5 = _T("");
	m_strPD6 = _T("");
	m_strPD7 = _T("");
	m_strPD8 = _T("");
	m_strPD9 = _T("");
	m_strPD10 = _T("");
	//}}AFX_DATA_INIT
	m_pDlgAnalyze = NULL;

}


void CUITeZheng4Dlg::DoDataExchange(CDataExchange* pDX)
{
	CTabPageSSL::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUITeZheng4Dlg)
	DDX_Text(pDX, IDC_EDIT_PIANDU1, m_strPD1);
	DDX_Text(pDX, IDC_EDIT_PIANDU2, m_strPD2);
	DDX_Text(pDX, IDC_EDIT_PIANDU3, m_strPD3);
	DDX_Text(pDX, IDC_EDIT_PIANDU4, m_strPD4);
	DDX_Text(pDX, IDC_EDIT_PIANDU5, m_strPD5);
	DDX_Text(pDX, IDC_EDIT_PIANDU6, m_strPD6);
	DDX_Text(pDX, IDC_EDIT_PIANDU7, m_strPD7);
	DDX_Text(pDX, IDC_EDIT_PIANDU8, m_strPD8);
	DDX_Text(pDX, IDC_EDIT_PIANDU9, m_strPD9);
	DDX_Text(pDX, IDC_EDIT_PIANDU10, m_strPD10);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUITeZheng4Dlg, CTabPageSSL)
	//{{AFX_MSG_MAP(CUITeZheng4Dlg)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU2, OnBtnTzPiandu2)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU3, OnBtnTzPiandu3)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU1, OnBtnTzPiandu1)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU4, OnBtnTzPiandu4)
	ON_BN_CLICKED(IDC_CHK_PIANDU1, OnChkPiandu1)
	ON_BN_CLICKED(IDC_CHK_PIANDU2, OnChkPiandu2)
	ON_BN_CLICKED(IDC_CHK_PIANDU3, OnChkPiandu3)
	ON_BN_CLICKED(IDC_CHK_PIANDU4, OnChkPiandu4)
	ON_BN_CLICKED(IDC_CHK_PIANDU5, OnChkPiandu5)
	ON_BN_CLICKED(IDC_CHK_PIANDU6, OnChkPiandu6)
	ON_BN_CLICKED(IDC_CHK_PIANDU7, OnChkPiandu7)
	ON_BN_CLICKED(IDC_CHK_PIANDU8, OnChkPiandu8)
	ON_BN_CLICKED(IDC_CHK_PIANDU9, OnChkPiandu9)
	ON_BN_CLICKED(IDC_CHK_PIANDU10, OnChkPiandu10)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU5, OnBtnTzPiandu5)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU6, OnBtnTzPiandu6)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU7, OnBtnTzPiandu7)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU8, OnBtnTzPiandu8)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU9, OnBtnTzPiandu9)
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU10, OnBtnTzPiandu10)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BTN_TZ_PIANDU10_YILOU, &CUITeZheng4Dlg::OnBnClickedBtnTzPiandu10Yilou)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUITeZheng4Dlg message handlers
CUITeZheng4Dlg::~CUITeZheng4Dlg()
{
	if (m_pDlgAnalyze)
	{
		delete m_pDlgAnalyze;
		m_pDlgAnalyze = NULL;
	}
}
void CUITeZheng4Dlg::ShowAnalyzeDlg()
{
	if (m_pDlgAnalyze)	
	{
		delete m_pDlgAnalyze;
		m_pDlgAnalyze = NULL;
	}

	m_pDlgAnalyze = new CUIAnalyzeDlg();
	m_pDlgAnalyze->Create(IDD_DIG_ANNALYZE,this);
	m_pDlgAnalyze->ShowWindow(SW_SHOW);
	CRect meRect;
	m_pDlgAnalyze->GetClientRect(&meRect);
	m_pDlgAnalyze->MoveWindow(G_RECT.left,G_RECT.bottom,
							  meRect.Width(),meRect.Height());

}
void CUITeZheng4Dlg::ShowChart(int nType)
{
	ShowAnalyzeDlg();

	CDataChart Data;
	Data.m_nYMax			= 22;
	Data.m_nYDiv			= 11;
	Data.m_nDataIndex		= nType; 
	Data.m_strYTitle		= G_SSQ_TZ_TITLE[Data.m_nDataIndex];
	Data.m_nType			= SSQ_TEZHENG_TYPE;
	m_pDlgAnalyze->m_DlgZouShi.SetChartData(Data);	

	Data.m_nYMin			= 0;
	Data.m_nYMax			= max_y_value(G_TZGL[Data.m_nDataIndex],60,G_END-G_START+1,Data.m_nYDiv);
	Data.m_nXMax			= num_value(G_TZGL[Data.m_nDataIndex],60);
	Data.m_strXTitle		= G_SSQ_TZ_TITLE[Data.m_nDataIndex];
	Data.m_strYTitle		= G_TZ_Y[Data.m_nDataIndex];
	m_pDlgAnalyze->m_DlgTongJi.SetChartData(Data);

	m_pDlgAnalyze->UpdateYuCeData(Data.m_nType,Data.m_nDataIndex);
}

bool CUITeZheng4Dlg::GetTZYuCe()
{
	ConvertStr2Int(m_strPD1, tz_pd1);
	ConvertStr2Int(m_strPD2, tz_pd2);
	ConvertStr2Int(m_strPD3, tz_pd3);
	ConvertStr2Int(m_strPD4, tz_pd4);
	ConvertStr2Int(m_strPD5, tz_pd5);
	ConvertStr2Int(m_strPD6, tz_pd6);
	ConvertStr2Int(m_strPD7, tz_pd7);
	ConvertStr2Int(m_strPD8, tz_pd8);
	ConvertStr2Int(m_strPD9, tz_pd9);
	ConvertStr2Int(m_strPD10, tz_pd10);

	return true;
}
bool CUITeZheng4Dlg::UpdateTZData()
{
	UpdateData(TRUE);
	
//	if (!CheckInputFormat())
//		return false;

	if (!((CButton*)GetDlgItem(IDC_CHK_PIANDU1))->GetCheck())
		m_strPD1.Empty();
	if (!((CButton*)GetDlgItem(IDC_CHK_PIANDU2))->GetCheck())
		m_strPD2.Empty();

	GetTZYuCe();
	
	return true;
}


void CUITeZheng4Dlg::OnBtnTzPiandu2() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD2_TYPE);
}

void CUITeZheng4Dlg::OnBtnTzPiandu3() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD3_TYPE);	
}

void CUITeZheng4Dlg::OnBtnTzPiandu1() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD1_TYPE);
}

void CUITeZheng4Dlg::OnBtnTzPiandu4() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD4_TYPE);	
}

void CUITeZheng4Dlg::OnChkPiandu1() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD1 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU1))->GetCheck();
	
}

void CUITeZheng4Dlg::OnChkPiandu2() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD2 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU2))->GetCheck();
	
}

void CUITeZheng4Dlg::OnChkPiandu3() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD3 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU3))->GetCheck();
	
}

void CUITeZheng4Dlg::OnChkPiandu4() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD4 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU4))->GetCheck();
	
}

void CUITeZheng4Dlg::OnChkPiandu5() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD5 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU5))->GetCheck();
}

void CUITeZheng4Dlg::OnChkPiandu6() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD6 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU6))->GetCheck();
}

void CUITeZheng4Dlg::OnChkPiandu7() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD7 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU7))->GetCheck();
	
}

void CUITeZheng4Dlg::OnChkPiandu8() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD8 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU8))->GetCheck();
	
}

void CUITeZheng4Dlg::OnChkPiandu9() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD9 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU9))->GetCheck();
	
}

void CUITeZheng4Dlg::OnChkPiandu10() 
{
	// TODO: Add your control notification handler code here
	G_CHECK_PD10 = ((CButton*)GetDlgItem(IDC_CHK_PIANDU10))->GetCheck();
	
}

void CUITeZheng4Dlg::OnBtnTzPiandu5() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD5_TYPE);	
	
}

void CUITeZheng4Dlg::OnBtnTzPiandu6() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD6_TYPE);	

}

void CUITeZheng4Dlg::OnBtnTzPiandu7() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD7_TYPE);	

}

void CUITeZheng4Dlg::OnBtnTzPiandu8() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD8_TYPE);	
	
}

void CUITeZheng4Dlg::OnBtnTzPiandu9() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD9_TYPE);	
	
}

void CUITeZheng4Dlg::OnBtnTzPiandu10() 
{
	// TODO: Add your control notification handler code here
	ShowChart(PD10_TYPE);	
	
}
bool CUITeZheng4Dlg::SetYuCeDataToFile(CString strFile)
{
	UpdateData(TRUE);
	if (strFile.IsEmpty())
		strFile = GetAppPath()+ETCFILENAME;

	CString strTmp;
	strTmp.Format("%d",G_CHECK_PD1);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD1",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD1)
	SetValueToEtcFile(strFile,"TEZHENG","PD1",(LPTSTR)(LPCTSTR)m_strPD1);

	strTmp.Format("%d",G_CHECK_PD2);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD2",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD2)
	SetValueToEtcFile(strFile,"TEZHENG","PD2",(LPTSTR)(LPCTSTR)m_strPD2);

	strTmp.Format("%d",G_CHECK_PD3);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD3",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD3)
	SetValueToEtcFile(strFile,"TEZHENG","PD3",(LPTSTR)(LPCTSTR)m_strPD3);

	strTmp.Format("%d",G_CHECK_PD4);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD4",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD4)
	SetValueToEtcFile(strFile,"TEZHENG","PD4",(LPTSTR)(LPCTSTR)m_strPD4);

	strTmp.Format("%d",G_CHECK_PD5);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD5",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD5)
	SetValueToEtcFile(strFile,"TEZHENG","PD5",(LPTSTR)(LPCTSTR)m_strPD5);

	strTmp.Format("%d",G_CHECK_PD6);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD6",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD6)
	SetValueToEtcFile(strFile,"TEZHENG","PD6",(LPTSTR)(LPCTSTR)m_strPD6);

	strTmp.Format("%d",G_CHECK_PD7);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD7",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD7)
	SetValueToEtcFile(strFile,"TEZHENG","PD7",(LPTSTR)(LPCTSTR)m_strPD7);

	strTmp.Format("%d",G_CHECK_PD8);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD8",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD8)
	SetValueToEtcFile(strFile,"TEZHENG","PD8",(LPTSTR)(LPCTSTR)m_strPD8);

	strTmp.Format("%d",G_CHECK_PD9);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD9",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD9)
	SetValueToEtcFile(strFile,"TEZHENG","PD9",(LPTSTR)(LPCTSTR)m_strPD9);

	strTmp.Format("%d",G_CHECK_PD10);
	SetValueToEtcFile(strFile,"TEZHENG","CHECK_PD10",(LPTSTR)(LPCTSTR)strTmp);
	if (G_CHECK_PD10)
	SetValueToEtcFile(strFile,"TEZHENG","PD10",(LPTSTR)(LPCTSTR)m_strPD10);
	
	return true;

}
bool CUITeZheng4Dlg::GetYuCeDataFromFile(CString strFile)
{
	if (strFile.IsEmpty())
		strFile = GetAppPath()+ETCFILENAME;
	int iRet = -1;
	char szValue[MAX_PATH+1] = {0};
	int iCheck = 0;
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD1",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD1",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD1 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD1)
		SendDlgItemMessage(IDC_CHK_PIANDU1,BM_CLICK,0,0);
	}
	else
	{
		m_strPD1.Empty();
		if (G_CHECK_PD1)
		SendDlgItemMessage(IDC_CHK_PIANDU1,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD2",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD2",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD2 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD2)
		SendDlgItemMessage(IDC_CHK_PIANDU2,BM_CLICK,0,0);
	}
	else
	{
		m_strPD2.Empty();
		if (G_CHECK_PD2)
		SendDlgItemMessage(IDC_CHK_PIANDU2,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD3",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD3",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD3 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD3)
		SendDlgItemMessage(IDC_CHK_PIANDU3,BM_CLICK,0,0);
	}
	else
	{
		m_strPD3.Empty();
		if (G_CHECK_PD3)
		SendDlgItemMessage(IDC_CHK_PIANDU3,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD4",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD4",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD4 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD4)
		SendDlgItemMessage(IDC_CHK_PIANDU4,BM_CLICK,0,0);
	}
	else
	{
		m_strPD4.Empty();
		if (G_CHECK_PD4)
		SendDlgItemMessage(IDC_CHK_PIANDU4,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD5",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD5",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD5 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD5)
		SendDlgItemMessage(IDC_CHK_PIANDU5,BM_CLICK,0,0);
	}
	else
	{
		m_strPD5.Empty();
		if (G_CHECK_PD5)
		SendDlgItemMessage(IDC_CHK_PIANDU5,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD6",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD6",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD6 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD6)
		SendDlgItemMessage(IDC_CHK_PIANDU6,BM_CLICK,0,0);
	}
	else
	{
		m_strPD6.Empty();
		if (G_CHECK_PD6)
		SendDlgItemMessage(IDC_CHK_PIANDU6,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD7",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD7",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD7 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD7)
		SendDlgItemMessage(IDC_CHK_PIANDU7,BM_CLICK,0,0);
	}
	else
	{
		m_strPD7.Empty();
		if (G_CHECK_PD7)
		SendDlgItemMessage(IDC_CHK_PIANDU7,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD8",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD8",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD8 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD8)
		SendDlgItemMessage(IDC_CHK_PIANDU8,BM_CLICK,0,0);
	}
	else
	{
		m_strPD8.Empty();
		if (G_CHECK_PD8)
		SendDlgItemMessage(IDC_CHK_PIANDU8,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD9",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD9",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD9 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD9)
		SendDlgItemMessage(IDC_CHK_PIANDU9,BM_CLICK,0,0);
	}
	else
	{
		m_strPD9.Empty();
		if (G_CHECK_PD9)
		SendDlgItemMessage(IDC_CHK_PIANDU9,BM_CLICK,0,0);
	}
	
	iCheck =0;
	GetIntValueFromEtcFile(strFile,"TEZHENG","CHECK_PD10",&iCheck);
	iRet = GetValueFromEtcFile(strFile,"TEZHENG","PD10",szValue,MAX_PATH);
	if ((iRet == ETC_OK) && (szValue[0] != '\0')&&iCheck)
	{
		m_strPD10 = szValue;
		memset(szValue,0,MAX_PATH+1);
		if (!G_CHECK_PD10)
		SendDlgItemMessage(IDC_CHK_PIANDU10,BM_CLICK,0,0);
	}
	else
	{
		m_strPD10.Empty();
		if (G_CHECK_PD10)
		SendDlgItemMessage(IDC_CHK_PIANDU10,BM_CLICK,0,0);
	}

	UpdateData(FALSE);
	
	return true;
}


void CUITeZheng4Dlg::OnBnClickedBtnTzPiandu10Yilou()
{
	theApp.ShowYiLouDlg(TZ_YILOU,PD10_TYPE);
}
